import pygame

import main


class Turtle(pygame.sprite.Sprite):

    def __init__(self):

        pygame.sprite.Sprite.__init__(self)
        # 生成左右朝向的乌龟图像
        self.Limage = pygame.image.load("images/turtle.png").convert_alpha()
        self.Rimage = pygame.transform.flip(self.Limage, True, False)
        # 保存原比例图像
        self.Limage1 = self.Limage
        self.Rimage1 = self.Rimage
        # 获取乌龟矩形区域
        self.rect = self.Limage.get_rect()
        # 乌龟大小级
        self.size = 1
        # 乌龟当前朝向(1:左  2:右)
        self.direction = 1
        # 乌龟得分
        self.score = 0
        # 乌龟生命
        self.live = True

    def bigger(self):
        if self.size == 3:
            # 1.4倍原比例大小
            self.Limage = pygame.transform.smoothscale(self.Limage1, \
                                                       (int(self.rect.width * 1.4), \
                                                        int(self.rect.height * 1.4)))
            self.Rimage = pygame.transform.flip(self.Limage, True, False)
        elif self.size == 5:
            # 1.8倍原比例大小
            self.Limage = pygame.transform.smoothscale(self.Limage1, \
                                                       (int(self.rect.width * 1.8), \
                                                        int(self.rect.height * 1.8)))
            self.Rimage = pygame.transform.flip(self.Limage, True, False)

    def display_turtle(self, pos1, pos2):
        if pos1[0] - pos2[0] > 0:
            main.screen.blit(self.Limage, self.rect)
            self.direction = 1
        elif pos1[0] - pos2[0] < 0:
            main.screen.blit(self.Rimage, self.rect)
            self.direction = 2
        elif pos1[0] - pos2[0] == 0:
            if self.direction == 1:
                main.screen.blit(self.Limage, self.rect)
            elif self.direction == 2:
                main.screen.blit(self.Rimage, self.rect)

